package com.ygqh.baby.solr;

import com.ygqh.baby.utils.LocalResourceBundle;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.SolrPingResponse;

import java.io.IOException;

/**
 * @author (guohao)
 * @version V1.0
 * @ClassName: SolrClent
 * @Description: 获取solr客户端
 * @date 2018年6月13日 下午3:00:53
 */
public enum YgSolrClient {
    /**
     *
     */
    INSTANCE;
    private SolrClient instance;

    YgSolrClient() {
        String addr = LocalResourceBundle.getConfigExtBundle().getString("solr.addr");
        System.out.println(addr);
//		addr = "http://39.106.248.97:8983/solr";
        instance = new HttpSolrClient.Builder(addr + "/product").build();
    }

    public SolrClient getSolrClient() {

        return instance;
    }

    public static void main(String[] args) throws SolrServerException, IOException {
        SolrClient solrClient = YgSolrClient.INSTANCE.getSolrClient();
        SolrPingResponse ping = solrClient.ping();
        System.out.println(ping);
    }

}
